//
//  CountdownView.m
//  test内付
//
//  Created by csh on 16/7/19.
//  Copyright © 2016年 陈世豪. All rights reserved.
//

#import "CountdownView.h"
#import "TimeCountView.h"
@interface CountdownView()
@property(nonatomic,weak)UILabel *statusLabel;
@property(nonatomic,weak)UILabel *desLabel;
@property(nonatomic,weak)TimeCountView *timeView;
@end
@implementation CountdownView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self=[super initWithFrame:frame]) {
        [self initUI];
        
        
    }
    return self;
}
-(void)setTimerModel:(TimerModel *)timerModel{
    _timerModel=timerModel;
    switch (timerModel.status) {
        case TimerStatusWillSale:
            self.statusLabel.text=@"即将开售";
            self.desLabel.text=@"距离开始时间";
            break;
            
        case TimerStatusSaleEnd:
            self.statusLabel.text=@"已售完";
            self.desLabel.text=@"再见";
            break;
        case TimerStatusisSaling:
            self.statusLabel.text=@"正在销售";
            self.desLabel.text=@"";
            break;
        default:
            break;
    }
    [self.timeView timerStartWithTime:timerModel.timeStamp];
}
-(void)initUI{
    UILabel *statusLabel=[[UILabel alloc]init];
    statusLabel.text=@"即将开售";
    statusLabel.textAlignment=NSTextAlignmentCenter;
    statusLabel.textColor=[UIColor redColor];
    statusLabel.font=[UIFont systemFontOfSize:15];
    [self addSubview:statusLabel];
    self.statusLabel=statusLabel;
    UILabel *desLabel=[[UILabel alloc]init];
    desLabel.text=@"距离开始时间";
    desLabel.textAlignment=NSTextAlignmentCenter;
    desLabel.font=[UIFont systemFontOfSize:10];
    desLabel.textColor=[UIColor lightGrayColor];
    [self addSubview:desLabel];
    self.desLabel=desLabel;
    TimeCountView *timeView=[[TimeCountView alloc]init];
    [self addSubview:timeView];
    self.timeView=timeView;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.statusLabel.frame=CGRectMake(0, 0, self.frame.size.width, 40);
    CGFloat desY=CGRectGetMaxY(self.statusLabel.frame);
    self.desLabel.frame=CGRectMake(0,desY, self.frame.size.width,30);
    CGFloat timeY=CGRectGetMaxY(self.desLabel.frame);
    self.timeView.frame=CGRectMake((self.frame.size.width-100)/2,timeY, 100, 40);
}
@end
